package com.project.service.impl;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.BuyInfoBean;
import com.project.bean.BuyOrderBean;
import com.project.bean.UserBean;
import com.project.mapper.IBuyInfoMapper;
import com.project.mapper.IBuyOrderMapper;
import com.project.service.IBuyOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

@Service
@Transactional
public class BuyOrderServiceImpl implements IBuyOrderService {
    @Autowired
    private IBuyOrderMapper buyOrderMapper;
    @Autowired
    private IBuyInfoMapper buyInfoMapper;
    @Override
    public IPage<BuyOrderBean> findByItem(Integer pageNO, String supplierName, LocalDate startDate, LocalDate endDate) {
        QueryWrapper<BuyOrderBean> qw = new QueryWrapper<>();
        if (supplierName !=null && supplierName.length() !=0){
            qw.like("bo_supplierName",supplierName);
        }
        if (startDate !=null){
            qw.ge("bo_date",startDate);
        }
        if (endDate !=null){
            qw.le("bo_date",endDate);
        }
        return buyOrderMapper.selectPage(new Page<>(pageNO,3),qw);
    }

    @Override
    public BuyOrderBean findById(Integer buyOrderId) {
        BuyOrderBean buyOrderBean = buyOrderMapper.selectById(buyOrderId);
        buyOrderBean.setBuyInfoBeanList(buyInfoMapper.findByBuyOrderId(buyOrderId));
        return buyOrderBean;
    }
}
